package com.itheima.controller;

import com.github.pagehelper.PageInfo;
import com.itheima.domain.Student;
import com.itheima.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @param
 * @return
 */
@RestController
@RequestMapping("/stu")
public class StudentController {
    //注入业务层service
    @Autowired
    private StudentService studentService;

    @RequestMapping("/findAll")
    public PageInfo findAll(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                            @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize) throws Exception {
        List<Student> list = studentService.findAll(pageNum, pageSize);
        PageInfo<Student> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    @RequestMapping("/add")
    public boolean add(@RequestBody Student student) throws Exception {
        boolean flag = studentService.add(student);
        return flag;
    }
    @RequestMapping("/update")
    public boolean update(@RequestBody Student student) throws Exception {
        boolean flag = studentService.update(student);
        return flag;
    }
    @RequestMapping("/delete")
    public boolean delete(String number) throws Exception {
        boolean flag = studentService.delete(number);
        return flag;
    }
}
